import java.awt.*;

// 子弹类
public class Bullet extends GameObject {
    public static final int SIZE = 8;

    private Tank.Direction direction;
    private int speed;
    private boolean isEnemy;

    public Bullet(int x, int y, int width, int height, Tank.Direction direction, int speed, boolean isEnemy) {
        super(x, y, width, height);
        this.direction = direction;
        this.speed = speed;
        this.isEnemy = isEnemy;
    }

    public void update() {
        switch(direction) {
            case UP: y -= speed; break;
            case DOWN: y += speed; break;
            case LEFT: x -= speed; break;
            case RIGHT: x += speed; break;
        }
    }

    public void draw(Graphics g) {
        g.setColor(isEnemy ? Color.RED : Color.YELLOW);
        g.fillOval(x, y, width, height);
    }

    public boolean isOutOfBounds() {
        return x < 0 || x > TankGame.WIDTH || y < 0 || y > TankGame.HEIGHT;
    }

    public boolean isEnemy() {
        return isEnemy;
    }

    // 添加 intersects 方法
    public boolean intersects(GameObject obj) {
        return x < obj.getX() + obj.getWidth() &&
                x + width > obj.getX() &&
                y < obj.getY() + obj.getHeight() &&
                y + height > obj.getY();
    }
}